﻿using System;
using System.Windows;
using System.Windows.Media;
using System.ComponentModel;

namespace MalRec.Base.Helper
{
    public static class VisualTreeHelperExtender
    {
        //public void eh()
        //{
        //    var bw = new BackgroundWorker();
        //    bw.DoWork += (s, e) =>
        //        {
        //            e.Result = "FUCK";
        //        };
        //    bw.RunWorkerCompleted += (s, e) =>
        //        {
        //            this.Title = e.Result;
        //        };
        //    bw.RunWorkerAsync();
        //}
        //public static T GetDescendantByType<T>(this Visual element) where T : Visual, new()
        //{
        //    if (element == null) return default(T);
        //    if (element.GetType() == typeof(T)) return (T)element;
        //    Visual foundElement = null;
        //    if (element is FrameworkElement)
        //    {
        //        (element as FrameworkElement).ApplyTemplate();
        //    }
        //    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
        //    {
        //        Visual visual = VisualTreeHelper.GetChild(element, i) as Visual;
        //        foundElement = visual.GetDescendantByType<T>();
        //        if (foundElement != null)
        //            break;
        //    }
        //    return (T)foundElement;
        //}
    }
}